package com.banzhi.shop.utils;

import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.banzhi.shop.R;
import com.squareup.picasso.Picasso;

import java.util.HashMap;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.wechat.friends.Wechat;
import cn.sharesdk.wechat.moments.WechatMoments;
import cn.sharesdk.wechat.utils.WechatHelper;

import static com.banzhi.shop.MyApp.context;

/**
 * Created by HT on 2017/5/23.
 */

public class ShareUtils {
    /**
     * 微信朋友圈分享
     */
    public static void wxPengyouquan(String title, String imaageUrl, String wxURL) {
        WechatHelper.ShareParams sp = new WechatMoments.ShareParams();
        sp.setTitle(title);
        if (imaageUrl != null) {
            sp.setImageUrl(imaageUrl);
        } else {
            sp.setImageData(((BitmapDrawable) context.getResources().getDrawable(R.mipmap.icon)).getBitmap());
        }
        sp.setUrl(wxURL);
        sp.setShareType(Platform.SHARE_WEBPAGE);
        Platform plat = ShareSDK.getPlatform(WechatMoments.NAME);
        plat.setPlatformActionListener(new PlatformActionListener() {
            @Override
            public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
                ToastUtils.makeToastShort("分享到朋友圈成功");
            }

            @Override
            public void onError(Platform platform, int i, Throwable throwable) {
                ToastUtils.makeToastShort("分享到朋友圈失败");
            }

            @Override
            public void onCancel(Platform platform, int i) {
                ToastUtils.makeToastShort("分享到朋友圈取消");
            }
        });
        plat.share(sp);
    }

    /**
     * 微信分享
     */
    public static void wxshare(String title, String imaageUrl, String text, String wxURL) {
        WechatHelper.ShareParams sp = new Wechat.ShareParams();
        sp.setTitle(title);
        if (imaageUrl != null) {
            sp.setImageUrl(imaageUrl);
        } else {
            sp.setImageData(((BitmapDrawable) context.getResources().getDrawable(R.mipmap.icon)).getBitmap());
        }
        sp.setText(text);
        sp.setUrl(wxURL);
        sp.setShareType(Platform.SHARE_WEBPAGE);
        Platform plat = ShareSDK.getPlatform(Wechat.NAME);
        plat.setPlatformActionListener(new PlatformActionListener() {
            @Override
            public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
                ToastUtils.makeToastShort("分享成功");
            }

            @Override
            public void onError(Platform platform, int i, Throwable throwable) {
                ToastUtils.makeToastShort("分享失败");
            }

            @Override
            public void onCancel(Platform platform, int i) {
                ToastUtils.makeToastShort("分享取消");
            }
        });
        plat.share(sp);
    }

    /**
     * 复制链接的方法
     */
    public static void copyLianjie(Activity activity, String wxURL) {
        //获取剪贴板管理器：
        ClipboardManager cm = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
        // 创建普通字符型ClipData
        ClipData mClipData = ClipData.newPlainText("Label", wxURL);
        // 将ClipData内容放到系统剪贴板里。
        cm.setPrimaryClip(mClipData);
        ToastUtils.makeToastShort("复制成功");
    }


    /**
     * 复制二维码的方法
     *
     * @param activity
     * @param title     标题
     * @param price     利润
     * @param Istime    是不是为特卖商品
     * @param Timestart 特卖开始时间
     * @param Timeend   特卖结束时间
     * @param imageurl  商品的URL地址
     * @param wxURL     商品的分享链接
     */
    public static void ereima(final Activity activity, String title, String price, String Istime, String Timestart, String Timeend, String imageurl, String wxURL) {
        FuzzyUtils fuzzyUtil = new FuzzyUtils(activity);
        //设置contentView
        View contentView = LayoutInflater.from(activity).inflate(R.layout.popupwindow_erweimashare, null);

        int width = activity.getResources().getDisplayMetrics().widthPixels;
        int height = activity.getResources().getDisplayMetrics().heightPixels;

        final PopupWindow popWindow = new PopupWindow(contentView, width, height);
        popWindow.setAnimationStyle(R.style.AnimBottom);

        popWindow.setFocusable(true);
        popWindow.setOutsideTouchable(false);// 设置允许在外点击消失
        //设置各个控件的点击响应
        ImageView ivimage = (ImageView) contentView.findViewById(R.id.iv_image);
        ImageView ivchacah = (ImageView) contentView.findViewById(R.id.iv_chacha);
        ImageView iverweima = (ImageView) contentView.findViewById(R.id.iv_erweima);
        TextView tvtitle = (TextView) contentView.findViewById(R.id.tv_tltle);
        TextView tvtime = (TextView) contentView.findViewById(R.id.tv_time);
        TextView tvmoney = (TextView) contentView.findViewById(R.id.tv_money);
        TextView tvtemai = (TextView) contentView.findViewById(R.id.tv_temai);
        TextView tvkaiqiang = (TextView) contentView.findViewById(R.id.tv_kaiqiang);
        TextView tvrenmingbi = (TextView) contentView.findViewById(R.id.tv_renmingbi);
        TextView tvcontent = (TextView) contentView.findViewById(R.id.tv_content);
        LinearLayout lltemaitime = (LinearLayout) contentView.findViewById(R.id.ll_temai_time);
        LinearLayout llsave = (LinearLayout) contentView.findViewById(R.id.ll_save);
        final LinearLayout ll = (LinearLayout) contentView.findViewById(R.id.ll);
        RelativeLayout rlbackground = (RelativeLayout) contentView.findViewById(R.id.rl_background);
        RelativeLayout rl = (RelativeLayout) contentView.findViewById(R.id.rl);
        rlbackground.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        });
        rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        tvtitle.setText(title);
        tvmoney.setText(NumberUtils.DecimalFormat(price));
        if ("1".equals(Istime)) {
            lltemaitime.setVisibility(View.VISIBLE);
            if (System.currentTimeMillis() / 1000 < Long.parseLong(Timestart)) {
                tvtime.setText(DateUtil.getTimeZhiData(Timestart).substring(8));
            } else if (System.currentTimeMillis() / 1000 > Long.parseLong(Timestart) && System.currentTimeMillis() / 1000 < Long.parseLong(Timeend)) {
                tvtime.setText("特卖正火热进行中");
                tvtemai.setVisibility(View.GONE);
                tvkaiqiang.setVisibility(View.GONE);
            } else {
                tvtime.setText("特卖活动已结束");
                tvtemai.setVisibility(View.GONE);
                tvkaiqiang.setVisibility(View.GONE);
            }
        } else {
            lltemaitime.setVisibility(View.INVISIBLE);
        }
        if (imageurl != null) {
            Picasso.with(activity).load(imageurl).placeholder(R.mipmap.zhanweitu2).into(ivimage);
        }

        ivchacah.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        });
        llsave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ll.setDrawingCacheEnabled(true);
                Bitmap tBitmap = ll.getDrawingCache();
                // 拷贝图片，否则在setDrawingCacheEnabled(false)以后该图片会被释放掉
                tBitmap = tBitmap.createBitmap(tBitmap);
                ll.setDrawingCacheEnabled(false);
                if (tBitmap != null) {
                    BitmapUtils.saveImageToGallery(activity, tBitmap);
                    ToastUtils.makeToastShort("保存图片成功");
                } else {
                    ToastUtils.makeToastShort("保存图片失败");
                }
                popWindow.dismiss();
            }
        });
        Bitmap codeBitMap = QRCodeUtil.createImage(wxURL, AndroidUtil.dip2px(activity, 200), AndroidUtil.dip2px(activity, 200), null);
        iverweima.setImageBitmap(codeBitMap);

        ColorDrawable dw = new ColorDrawable(0x70000000);
        popWindow.setBackgroundDrawable(new BitmapDrawable(fuzzyUtil.blur()));
        popWindow.showAtLocation(contentView, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
    }
    //商品二维码
    public static void ereima2(final Activity activity, String title, String price, String Istime, String Timestart, String Timeend, String imageurl, String wxURL) {
        FuzzyUtils fuzzyUtil = new FuzzyUtils(activity);
        //设置contentView
        View contentView = LayoutInflater.from(activity).inflate(R.layout.popupwindow_erweimashare2, null);

        int width = activity.getResources().getDisplayMetrics().widthPixels;
        int height = activity.getResources().getDisplayMetrics().heightPixels;

        final PopupWindow popWindow = new PopupWindow(contentView, width, height);
        popWindow.setAnimationStyle(R.style.AnimBottom);

        popWindow.setFocusable(true);
        popWindow.setOutsideTouchable(false);// 设置允许在外点击消失
        //设置各个控件的点击响应
        ImageView ivimage = (ImageView) contentView.findViewById(R.id.iv_image);
        ImageView ivchacah = (ImageView) contentView.findViewById(R.id.iv_chacha);
        ImageView iverweima = (ImageView) contentView.findViewById(R.id.iv_erweima);
        TextView tvtitle = (TextView) contentView.findViewById(R.id.tv_tltle);
      //  TextView tvtime = (TextView) contentView.findViewById(R.id.tv_time);
        TextView tvmoney = (TextView) contentView.findViewById(R.id.tv_money);
       // TextView tvtemai = (TextView) contentView.findViewById(R.id.tv_temai);
       // TextView tvkaiqiang = (TextView) contentView.findViewById(R.id.tv_kaiqiang);
       // TextView tvrenmingbi = (TextView) contentView.findViewById(R.id.tv_renmingbi);
       // TextView tvcontent = (TextView) contentView.findViewById(R.id.tv_content);
       // LinearLayout lltemaitime = (LinearLayout) contentView.findViewById(R.id.ll_temai_time);
        LinearLayout llsave = (LinearLayout) contentView.findViewById(R.id.ll_save);
        final LinearLayout ll = (LinearLayout) contentView.findViewById(R.id.ll);
        RelativeLayout rlbackground = (RelativeLayout) contentView.findViewById(R.id.rl_background);
        RelativeLayout rl = (RelativeLayout) contentView.findViewById(R.id.rl);
        rlbackground.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        });
        rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        tvtitle.setText(title);
        tvmoney.setText(NumberUtils.DecimalFormat(price));
 /*       if ("1".equals(Istime)) {
            lltemaitime.setVisibility(View.VISIBLE);
            if (System.currentTimeMillis() / 1000 < Long.parseLong(Timestart)) {
                tvtime.setText(DateUtil.getTimeZhiData(Timestart).substring(8));
            } else if (System.currentTimeMillis() / 1000 > Long.parseLong(Timestart) && System.currentTimeMillis() / 1000 < Long.parseLong(Timeend)) {
                tvtime.setText("特卖正火热进行中");
                tvtemai.setVisibility(View.GONE);
                tvkaiqiang.setVisibility(View.GONE);
            } else {
                tvtime.setText("特卖活动已结束");
                tvtemai.setVisibility(View.GONE);
                tvkaiqiang.setVisibility(View.GONE);
            }
        } else {
            lltemaitime.setVisibility(View.INVISIBLE);
        }*/
        if (imageurl != null) {
            Picasso.with(activity).load(imageurl).placeholder(R.mipmap.zhanweitu2).into(ivimage);
        }

        ivchacah.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        });
        llsave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ll.setDrawingCacheEnabled(true);
                Bitmap tBitmap = ll.getDrawingCache();
                // 拷贝图片，否则在setDrawingCacheEnabled(false)以后该图片会被释放掉
                tBitmap = tBitmap.createBitmap(tBitmap);
                ll.setDrawingCacheEnabled(false);
                if (tBitmap != null) {
                    BitmapUtils.saveImageToGallery(activity, tBitmap);
                    ToastUtils.makeToastShort("保存图片成功");
                } else {
                    ToastUtils.makeToastShort("保存图片失败");
                }
                popWindow.dismiss();
            }
        });
        Bitmap codeBitMap = QRCodeUtil.createImage(wxURL, AndroidUtil.dip2px(activity, 200), AndroidUtil.dip2px(activity, 200), null);
        iverweima.setImageBitmap(codeBitMap);

        ColorDrawable dw = new ColorDrawable(0x70000000);
        popWindow.setBackgroundDrawable(new BitmapDrawable(fuzzyUtil.blur()));
        popWindow.showAtLocation(contentView, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
    }
    public static void ereima3(final Activity activity, String title, String price, String Istime, String Timestart, String Timeend, String imageurl, String wxURL) {
        FuzzyUtils fuzzyUtil = new FuzzyUtils(activity);
        //设置contentView
        View contentView = LayoutInflater.from(activity).inflate(R.layout.popupwindow_erweimashare3, null);

        int width = activity.getResources().getDisplayMetrics().widthPixels;
        int height = activity.getResources().getDisplayMetrics().heightPixels;

        final PopupWindow popWindow = new PopupWindow(contentView, width, height);
        popWindow.setAnimationStyle(R.style.AnimBottom);

        popWindow.setFocusable(true);
        popWindow.setOutsideTouchable(false);// 设置允许在外点击消失
        //设置各个控件的点击响应
        ImageView ivimage = (ImageView) contentView.findViewById(R.id.iv_image);
        ImageView ivchacah = (ImageView) contentView.findViewById(R.id.iv_chacha);
        ImageView iverweima = (ImageView) contentView.findViewById(R.id.iv_erweima);
        TextView tvtitle = (TextView) contentView.findViewById(R.id.tv_tltle);
        //  TextView tvtime = (TextView) contentView.findViewById(R.id.tv_time);
        TextView tvmoney = (TextView) contentView.findViewById(R.id.tv_money);
        // TextView tvtemai = (TextView) contentView.findViewById(R.id.tv_temai);
        // TextView tvkaiqiang = (TextView) contentView.findViewById(R.id.tv_kaiqiang);
        // TextView tvrenmingbi = (TextView) contentView.findViewById(R.id.tv_renmingbi);
        // TextView tvcontent = (TextView) contentView.findViewById(R.id.tv_content);
        // LinearLayout lltemaitime = (LinearLayout) contentView.findViewById(R.id.ll_temai_time);
        LinearLayout llsave = (LinearLayout) contentView.findViewById(R.id.ll_save);
        final LinearLayout ll = (LinearLayout) contentView.findViewById(R.id.ll);
        RelativeLayout rlbackground = (RelativeLayout) contentView.findViewById(R.id.rl_background);
        RelativeLayout rl = (RelativeLayout) contentView.findViewById(R.id.rl);
        rlbackground.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        });
        rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        tvtitle.setText(title);
        tvmoney.setText(NumberUtils.DecimalFormat(price));
 /*       if ("1".equals(Istime)) {
            lltemaitime.setVisibility(View.VISIBLE);
            if (System.currentTimeMillis() / 1000 < Long.parseLong(Timestart)) {
                tvtime.setText(DateUtil.getTimeZhiData(Timestart).substring(8));
            } else if (System.currentTimeMillis() / 1000 > Long.parseLong(Timestart) && System.currentTimeMillis() / 1000 < Long.parseLong(Timeend)) {
                tvtime.setText("特卖正火热进行中");
                tvtemai.setVisibility(View.GONE);
                tvkaiqiang.setVisibility(View.GONE);
            } else {
                tvtime.setText("特卖活动已结束");
                tvtemai.setVisibility(View.GONE);
                tvkaiqiang.setVisibility(View.GONE);
            }
        } else {
            lltemaitime.setVisibility(View.INVISIBLE);
        }*/
        if (imageurl != null) {
            Picasso.with(activity).load(imageurl).placeholder(R.mipmap.zhanweitu2).into(ivimage);
        }

        ivchacah.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        });
        llsave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ll.setDrawingCacheEnabled(true);
                Bitmap tBitmap = ll.getDrawingCache();
                // 拷贝图片，否则在setDrawingCacheEnabled(false)以后该图片会被释放掉
                tBitmap = tBitmap.createBitmap(tBitmap);
                ll.setDrawingCacheEnabled(false);
                if (tBitmap != null) {
                    BitmapUtils.saveImageToGallery(activity, tBitmap);
                    ToastUtils.makeToastShort("保存图片成功");
                } else {
                    ToastUtils.makeToastShort("保存图片失败");
                }
                popWindow.dismiss();
            }
        });
        Bitmap codeBitMap = QRCodeUtil.createImage(wxURL, AndroidUtil.dip2px(activity, 200), AndroidUtil.dip2px(activity, 200), null);
        iverweima.setImageBitmap(codeBitMap);

        ColorDrawable dw = new ColorDrawable(0x70000000);
        popWindow.setBackgroundDrawable(new BitmapDrawable(fuzzyUtil.blur()));
        popWindow.showAtLocation(contentView, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
    }
    //拼团中商品分享
    public static void ereima4(final Activity activity, String title, String price, String Istime, String Timestart, String Timeend, String imageurl, String wxURL) {
        FuzzyUtils fuzzyUtil = new FuzzyUtils(activity);
        //设置contentView
        View contentView = LayoutInflater.from(activity).inflate(R.layout.popupwindow_erweimashare4, null);

        int width = activity.getResources().getDisplayMetrics().widthPixels;
        int height = activity.getResources().getDisplayMetrics().heightPixels;

        final PopupWindow popWindow = new PopupWindow(contentView, width, height);
        popWindow.setAnimationStyle(R.style.AnimBottom);

        popWindow.setFocusable(true);
        popWindow.setOutsideTouchable(false);// 设置允许在外点击消失
        //设置各个控件的点击响应
        ImageView ivimage = (ImageView) contentView.findViewById(R.id.iv_image);
        ImageView ivchacah = (ImageView) contentView.findViewById(R.id.iv_chacha);
        ImageView iverweima = (ImageView) contentView.findViewById(R.id.iv_erweima);
        TextView tvtitle = (TextView) contentView.findViewById(R.id.tv_tltle);
        //  TextView tvtime = (TextView) contentView.findViewById(R.id.tv_time);
        TextView tvmoney = (TextView) contentView.findViewById(R.id.tv_money);
        // TextView tvtemai = (TextView) contentView.findViewById(R.id.tv_temai);
        // TextView tvkaiqiang = (TextView) contentView.findViewById(R.id.tv_kaiqiang);
        // TextView tvrenmingbi = (TextView) contentView.findViewById(R.id.tv_renmingbi);
        // TextView tvcontent = (TextView) contentView.findViewById(R.id.tv_content);
        // LinearLayout lltemaitime = (LinearLayout) contentView.findViewById(R.id.ll_temai_time);
        LinearLayout llsave = (LinearLayout) contentView.findViewById(R.id.ll_save);
        final LinearLayout ll = (LinearLayout) contentView.findViewById(R.id.ll);
        RelativeLayout rlbackground = (RelativeLayout) contentView.findViewById(R.id.rl_background);
        RelativeLayout rl = (RelativeLayout) contentView.findViewById(R.id.rl);
        rlbackground.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        });
        rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        tvtitle.setText(title);
        tvmoney.setText(NumberUtils.DecimalFormat(price));
 /*       if ("1".equals(Istime)) {
            lltemaitime.setVisibility(View.VISIBLE);
            if (System.currentTimeMillis() / 1000 < Long.parseLong(Timestart)) {
                tvtime.setText(DateUtil.getTimeZhiData(Timestart).substring(8));
            } else if (System.currentTimeMillis() / 1000 > Long.parseLong(Timestart) && System.currentTimeMillis() / 1000 < Long.parseLong(Timeend)) {
                tvtime.setText("特卖正火热进行中");
                tvtemai.setVisibility(View.GONE);
                tvkaiqiang.setVisibility(View.GONE);
            } else {
                tvtime.setText("特卖活动已结束");
                tvtemai.setVisibility(View.GONE);
                tvkaiqiang.setVisibility(View.GONE);
            }
        } else {
            lltemaitime.setVisibility(View.INVISIBLE);
        }*/
        if (imageurl != null) {
            Picasso.with(activity).load(imageurl).placeholder(R.mipmap.zhanweitu2).into(ivimage);
        }

        ivchacah.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        });
        llsave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ll.setDrawingCacheEnabled(true);
                Bitmap tBitmap = ll.getDrawingCache();
                // 拷贝图片，否则在setDrawingCacheEnabled(false)以后该图片会被释放掉
                tBitmap = tBitmap.createBitmap(tBitmap);
                ll.setDrawingCacheEnabled(false);
                if (tBitmap != null) {
                    BitmapUtils.saveImageToGallery(activity, tBitmap);
                    ToastUtils.makeToastShort("保存图片成功");
                } else {
                    ToastUtils.makeToastShort("保存图片失败");
                }
                popWindow.dismiss();
            }
        });
        Bitmap codeBitMap = QRCodeUtil.createImage(wxURL, AndroidUtil.dip2px(activity, 200), AndroidUtil.dip2px(activity, 200), null);
        iverweima.setImageBitmap(codeBitMap);

        ColorDrawable dw = new ColorDrawable(0x70000000);
        popWindow.setBackgroundDrawable(new BitmapDrawable(fuzzyUtil.blur()));
        popWindow.showAtLocation(contentView, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
    }

    /**
     * 复制二维码的方法
     *
     * @param activity
     * @param title     标题
     * @param price     利润
     * @param Istime    是不是为特卖商品
     * @param Timestart 特卖开始时间
     * @param Timeend   特卖结束时间
     * @param imageurl  商品的URL地址
     * @param wxURL     商品的分享链接
     */
    public static void ereimakaidian6(final Activity activity, String title, String price, String Istime, String Timestart, String Timeend, String imageurl, String wxURL) {
        FuzzyUtils fuzzyUtil = new FuzzyUtils(activity);
        //设置contentView
        View contentView = LayoutInflater.from(activity).inflate(R.layout.popupwindow_erweimashare_dianpu6, null);

        int width = activity.getResources().getDisplayMetrics().widthPixels;
        int height = activity.getResources().getDisplayMetrics().heightPixels;

        final PopupWindow popWindow = new PopupWindow(contentView, width, height);
        popWindow.setAnimationStyle(R.style.AnimBottom);

        popWindow.setFocusable(true);
        popWindow.setOutsideTouchable(false);// 设置允许在外点击消失
        //设置各个控件的点击响应
        ImageView ivimage = (ImageView) contentView.findViewById(R.id.iv_image);
        ImageView ivchacah = (ImageView) contentView.findViewById(R.id.iv_chacha);
        ImageView iverweima = (ImageView) contentView.findViewById(R.id.iv_erweima);
        TextView tvtitle = (TextView) contentView.findViewById(R.id.tv_tltle);

        LinearLayout llsave = (LinearLayout) contentView.findViewById(R.id.ll_save);
        final LinearLayout ll = (LinearLayout) contentView.findViewById(R.id.ll);
        RelativeLayout rlbackground = (RelativeLayout) contentView.findViewById(R.id.rl_background);
        RelativeLayout rl = (RelativeLayout) contentView.findViewById(R.id.rl);
        rlbackground.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        });
        rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        tvtitle.setText(title);
        if (ASUtils.isCanUse(imageurl)) {
            Picasso.with(activity).load(imageurl).placeholder(R.mipmap.zhanweitu2).into(ivimage);
        } else {
            ivimage.setImageResource(R.mipmap.yaoqin);
        }
        ivchacah.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        });
        llsave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ll.setDrawingCacheEnabled(true);
                Bitmap tBitmap = ll.getDrawingCache();
                // 拷贝图片，否则在setDrawingCacheEnabled(false)以后该图片会被释放掉
                tBitmap = tBitmap.createBitmap(tBitmap);
                ll.setDrawingCacheEnabled(false);
                if (tBitmap != null) {
                    BitmapUtils.saveImageToGallery(activity, tBitmap);
                    ToastUtils.makeToastShort("保存图片成功");
                } else {
                    ToastUtils.makeToastShort("保存图片失败");
                }
                popWindow.dismiss();
            }
        });
        Bitmap codeBitMap = QRCodeUtil.createImage(wxURL, AndroidUtil.dip2px(activity, 200), AndroidUtil.dip2px(activity, 200), null);
        iverweima.setImageBitmap(codeBitMap);

        ColorDrawable dw = new ColorDrawable(0x70000000);
        popWindow.setBackgroundDrawable(new BitmapDrawable(fuzzyUtil.blur()));
        popWindow.showAtLocation(contentView, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
    }
    public static void ereimakaidian(final Activity activity, String title, String price, String Istime, String Timestart, String Timeend, String imageurl, String wxURL) {
        FuzzyUtils fuzzyUtil = new FuzzyUtils(activity);
        //设置contentView
        View contentView = LayoutInflater.from(activity).inflate(R.layout.popupwindow_erweimashare_dianpu, null);

        int width = activity.getResources().getDisplayMetrics().widthPixels;
        int height = activity.getResources().getDisplayMetrics().heightPixels;

        final PopupWindow popWindow = new PopupWindow(contentView, width, height);
        popWindow.setAnimationStyle(R.style.AnimBottom);

        popWindow.setFocusable(true);
        popWindow.setOutsideTouchable(false);// 设置允许在外点击消失
        //设置各个控件的点击响应
        ImageView ivimage = (ImageView) contentView.findViewById(R.id.iv_image);
        ImageView ivchacah = (ImageView) contentView.findViewById(R.id.iv_chacha);
        ImageView iverweima = (ImageView) contentView.findViewById(R.id.iv_erweima);
        TextView tvtitle = (TextView) contentView.findViewById(R.id.tv_tltle);

        LinearLayout llsave = (LinearLayout) contentView.findViewById(R.id.ll_save);
        final LinearLayout ll = (LinearLayout) contentView.findViewById(R.id.ll);
        RelativeLayout rlbackground = (RelativeLayout) contentView.findViewById(R.id.rl_background);
        RelativeLayout rl = (RelativeLayout) contentView.findViewById(R.id.rl);
        rlbackground.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        });
        rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        tvtitle.setText(title);
        if (ASUtils.isCanUse(imageurl)) {
            Picasso.with(activity).load(imageurl).placeholder(R.mipmap.zhanweitu2).into(ivimage);
        } else {
            ivimage.setImageResource(R.mipmap.yaoqin);
        }
        ivchacah.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        });
        llsave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ll.setDrawingCacheEnabled(true);
                Bitmap tBitmap = ll.getDrawingCache();
                // 拷贝图片，否则在setDrawingCacheEnabled(false)以后该图片会被释放掉
                tBitmap = tBitmap.createBitmap(tBitmap);
                ll.setDrawingCacheEnabled(false);
                if (tBitmap != null) {
                    BitmapUtils.saveImageToGallery(activity, tBitmap);
                    ToastUtils.makeToastShort("保存图片成功");
                } else {
                    ToastUtils.makeToastShort("保存图片失败");
                }
                popWindow.dismiss();
            }
        });
        Bitmap codeBitMap = QRCodeUtil.createImage(wxURL, AndroidUtil.dip2px(activity, 200), AndroidUtil.dip2px(activity, 200), null);
        iverweima.setImageBitmap(codeBitMap);

        ColorDrawable dw = new ColorDrawable(0x70000000);
        popWindow.setBackgroundDrawable(new BitmapDrawable(fuzzyUtil.blur()));
        popWindow.showAtLocation(contentView, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
    }
    //店铺分享
    public static void ereimakaidian2(final Activity activity, String title, String price, String Istime, String Timestart, String Timeend, String imageurl, String wxURL) {
        FuzzyUtils fuzzyUtil = new FuzzyUtils(activity);
        //设置contentView
        View contentView = LayoutInflater.from(activity).inflate(R.layout.jf, null);

        int width = activity.getResources().getDisplayMetrics().widthPixels;
        int height = activity.getResources().getDisplayMetrics().heightPixels;

        final PopupWindow popWindow = new PopupWindow(contentView, width, height);
        popWindow.setAnimationStyle(R.style.AnimBottom);

        popWindow.setFocusable(true);
        popWindow.setOutsideTouchable(false);// 设置允许在外点击消失
        //设置各个控件的点击响应
        ImageView ivimage = (ImageView) contentView.findViewById(R.id.iv_image);
        ImageView ivchacah = (ImageView) contentView.findViewById(R.id.iv_chacha);
        ImageView iverweima = (ImageView) contentView.findViewById(R.id.iv_erweima);
        TextView tvtitle = (TextView) contentView.findViewById(R.id.tv_tltle);

        LinearLayout llsave = (LinearLayout) contentView.findViewById(R.id.ll_save);
     final LinearLayout ll = (LinearLayout) contentView.findViewById(R.id.ll);
    //    RelativeLayout rlbackground = (RelativeLayout) contentView.findViewById(R.id.rl_background);
     //   RelativeLayout rl = (RelativeLayout) contentView.findViewById(R.id.rl);
   /*  rlbackground.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        });*/
      /*  ivchacah.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });*/
        tvtitle.setText(title);
        if (ASUtils.isCanUse(imageurl)) {
            Picasso.with(activity).load(imageurl).placeholder(R.mipmap.zhanweitu2).into(ivimage);
        } else {
           // Picasso.with(activity).load(imageurl).placeholder(R.mipmap.zhanweitu2).into(ivimage);
            ivimage.setImageResource(R.mipmap.store_share);
        }
        ivchacah.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        });
        llsave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ll.setDrawingCacheEnabled(true);
                Bitmap tBitmap = ll.getDrawingCache();
                // 拷贝图片，否则在setDrawingCacheEnabled(false)以后该图片会被释放掉
                tBitmap = tBitmap.createBitmap(tBitmap);
                ll.setDrawingCacheEnabled(false);
                if (tBitmap != null) {
                    BitmapUtils.saveImageToGallery(activity, tBitmap);
                    ToastUtils.makeToastShort("保存图片成功");
                } else {
                    ToastUtils.makeToastShort("保存图片失败");
                }
                popWindow.dismiss();
            }
        });
        Bitmap codeBitMap = QRCodeUtil.createImage(wxURL, AndroidUtil.dip2px(activity, 200), AndroidUtil.dip2px(activity, 200), null);
        iverweima.setImageBitmap(codeBitMap);

        ColorDrawable dw = new ColorDrawable(0x70000000);
        popWindow.setBackgroundDrawable(new BitmapDrawable(fuzzyUtil.blur()));
        popWindow.showAtLocation(contentView, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
    }
    //店长邀请分享
    public static void ereimakaidian3(final Activity activity, String title, String price, String Istime, String Timestart, String Timeend, String imageurl, String wxURL) {
        FuzzyUtils fuzzyUtil = new FuzzyUtils(activity);
        //设置contentView
        View contentView = LayoutInflater.from(activity).inflate(R.layout.popupwindow_erweimashare_dianpu3, null);

        int width = activity.getResources().getDisplayMetrics().widthPixels;
        int height = activity.getResources().getDisplayMetrics().heightPixels;

        final PopupWindow popWindow = new PopupWindow(contentView, width, height);
        popWindow.setAnimationStyle(R.style.AnimBottom);

        popWindow.setFocusable(true);
        popWindow.setOutsideTouchable(false);// 设置允许在外点击消失
        //设置各个控件的点击响应
        ImageView ivimage = (ImageView) contentView.findViewById(R.id.iv_image);
        ImageView ivchacah = (ImageView) contentView.findViewById(R.id.iv_chacha);
        ImageView iverweima = (ImageView) contentView.findViewById(R.id.iv_erweima);
        TextView tvtitle = (TextView) contentView.findViewById(R.id.tv_tltle);

        LinearLayout llsave = (LinearLayout) contentView.findViewById(R.id.ll_save);
        final LinearLayout ll = (LinearLayout) contentView.findViewById(R.id.ll);
        RelativeLayout rlbackground = (RelativeLayout) contentView.findViewById(R.id.rl_background);
        RelativeLayout rl = (RelativeLayout) contentView.findViewById(R.id.rl);
        rlbackground.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        });
        rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        tvtitle.setText(title);

        if (ASUtils.isCanUse(imageurl)) {
            Picasso.with(activity).load(R.mipmap.store_share).placeholder(R.mipmap.zhanweitu2).into(ivimage);
        } else {
            ivimage.setImageResource(R.mipmap.store_share);
        }
        ivchacah.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        });
        llsave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ll.setDrawingCacheEnabled(true);
                Bitmap tBitmap = ll.getDrawingCache();
                // 拷贝图片，否则在setDrawingCacheEnabled(false)以后该图片会被释放掉
                tBitmap = tBitmap.createBitmap(tBitmap);
                ll.setDrawingCacheEnabled(false);
                if (tBitmap != null) {
                    BitmapUtils.saveImageToGallery(activity, tBitmap);
                    ToastUtils.makeToastShort("保存图片成功");
                } else {
                    ToastUtils.makeToastShort("保存图片失败");
                }
                popWindow.dismiss();
            }
        });
        Bitmap codeBitMap = QRCodeUtil.createImage(wxURL, AndroidUtil.dip2px(activity, 200), AndroidUtil.dip2px(activity, 200), null);
        iverweima.setImageBitmap(codeBitMap);

        ColorDrawable dw = new ColorDrawable(0x70000000);
        popWindow.setBackgroundDrawable(new BitmapDrawable(fuzzyUtil.blur()));
        popWindow.showAtLocation(contentView, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
    }
    //店长邀请分享
    public static void ereimakaidian5(final Activity activity, String title, String price, String Istime, String Timestart, String Timeend, String imageurl, String wxURL) {
        FuzzyUtils fuzzyUtil = new FuzzyUtils(activity);
        //设置contentView
        View contentView = LayoutInflater.from(activity).inflate(R.layout.popupwindow_erweimashare_dianpu3, null);

        int width = activity.getResources().getDisplayMetrics().widthPixels;
        int height = activity.getResources().getDisplayMetrics().heightPixels;

        final PopupWindow popWindow = new PopupWindow(contentView, width, height);
        popWindow.setAnimationStyle(R.style.AnimBottom);

        popWindow.setFocusable(true);
        popWindow.setOutsideTouchable(false);// 设置允许在外点击消失
        //设置各个控件的点击响应
        ImageView ivimage = (ImageView) contentView.findViewById(R.id.iv_image);
        ImageView ivchacah = (ImageView) contentView.findViewById(R.id.iv_chacha);
        ImageView iverweima = (ImageView) contentView.findViewById(R.id.iv_erweima);
        TextView tvtitle = (TextView) contentView.findViewById(R.id.tv_tltle);

        LinearLayout llsave = (LinearLayout) contentView.findViewById(R.id.ll_save);
        final LinearLayout ll = (LinearLayout) contentView.findViewById(R.id.ll);
        RelativeLayout rlbackground = (RelativeLayout) contentView.findViewById(R.id.rl_background);
        RelativeLayout rl = (RelativeLayout) contentView.findViewById(R.id.rl);
        rlbackground.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        });
        rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        tvtitle.setText(title);

        if (ASUtils.isCanUse(imageurl)) {
            Picasso.with(activity).load(R.mipmap.store_share).placeholder(R.mipmap.zhanweitu2).into(ivimage);
        } else {
            ivimage.setImageResource(R.mipmap.store_share);
        }
        ivchacah.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        });
        llsave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ll.setDrawingCacheEnabled(true);
                Bitmap tBitmap = ll.getDrawingCache();
                // 拷贝图片，否则在setDrawingCacheEnabled(false)以后该图片会被释放掉
                tBitmap = tBitmap.createBitmap(tBitmap);
                ll.setDrawingCacheEnabled(false);
                if (tBitmap != null) {
                    BitmapUtils.saveImageToGallery(activity, tBitmap);
                    ToastUtils.makeToastShort("保存图片成功");
                } else {
                    ToastUtils.makeToastShort("保存图片失败");
                }
                popWindow.dismiss();
            }
        });
        Bitmap codeBitMap = QRCodeUtil.createImage(wxURL, AndroidUtil.dip2px(activity, 200), AndroidUtil.dip2px(activity, 200), null);
        iverweima.setImageBitmap(codeBitMap);

        ColorDrawable dw = new ColorDrawable(0x70000000);
        popWindow.setBackgroundDrawable(new BitmapDrawable(fuzzyUtil.blur()));
        popWindow.showAtLocation(contentView, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
    }
   // 店铺分享
    public static void ereimakaidian4(final Activity activity, String title, String price, String Istime, String Timestart, String Timeend, String imageurl, String wxURL) {
        FuzzyUtils fuzzyUtil = new FuzzyUtils(activity);
        //设置contentView
        View contentView = LayoutInflater.from(activity).inflate(R.layout.popupwindow_erweimashare_dianpu4, null);

        int width = activity.getResources().getDisplayMetrics().widthPixels;
        int height = activity.getResources().getDisplayMetrics().heightPixels;

        final PopupWindow popWindow = new PopupWindow(contentView, width, height);
        popWindow.setAnimationStyle(R.style.AnimBottom);

        popWindow.setFocusable(true);
        popWindow.setOutsideTouchable(false);// 设置允许在外点击消失
        //设置各个控件的点击响应
        ImageView ivimage = (ImageView) contentView.findViewById(R.id.iv_image);
        ImageView ivchacah = (ImageView) contentView.findViewById(R.id.iv_chacha);
        ImageView iverweima = (ImageView) contentView.findViewById(R.id.iv_erweima);
        TextView tvtitle = (TextView) contentView.findViewById(R.id.tv_tltle);

        LinearLayout llsave = (LinearLayout) contentView.findViewById(R.id.ll_save);
        final LinearLayout ll = (LinearLayout) contentView.findViewById(R.id.ll);
        RelativeLayout rlbackground = (RelativeLayout) contentView.findViewById(R.id.rl_background);
        RelativeLayout rl = (RelativeLayout) contentView.findViewById(R.id.rl);
        rlbackground.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        });
        rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        tvtitle.setText(title);

        if (ASUtils.isCanUse(imageurl)) {
            Picasso.with(activity).load(imageurl).placeholder(R.mipmap.zhanweitu2).into(ivimage);
        } else {
            ivimage.setImageResource(R.mipmap.store_share);
        }
        ivchacah.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        });
        llsave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ll.setDrawingCacheEnabled(true);
                Bitmap tBitmap = ll.getDrawingCache();
                // 拷贝图片，否则在setDrawingCacheEnabled(false)以后该图片会被释放掉
                tBitmap = tBitmap.createBitmap(tBitmap);
                ll.setDrawingCacheEnabled(false);
                if (tBitmap != null) {
                    BitmapUtils.saveImageToGallery(activity, tBitmap);
                    ToastUtils.makeToastShort("保存图片成功");
                } else {
                    ToastUtils.makeToastShort("保存图片失败");
                }
                popWindow.dismiss();
            }
        });
        Bitmap codeBitMap = QRCodeUtil.createImage(wxURL, AndroidUtil.dip2px(activity, 200), AndroidUtil.dip2px(activity, 200), null);
        iverweima.setImageBitmap(codeBitMap);

        ColorDrawable dw = new ColorDrawable(0x70000000);
        popWindow.setBackgroundDrawable(new BitmapDrawable(fuzzyUtil.blur()));
        popWindow.showAtLocation(contentView, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
    }
}